package com.chiyoyo.rabbitmq.framework.service.impl;

import com.chiyoyo.rabbitmq.framework.annotation.RabbitMq;
import com.chiyoyo.rabbitmq.framework.service.AbstractMQService;
import org.springframework.amqp.core.*;
import org.springframework.stereotype.Service;

/**
 * @author chil
 * RabbitMq主题队列注册
 */
@Service("topicMQService")
public class TopicMQService extends AbstractMQService {

    @Override
    protected AbstractExchange initExchange(String exchangeName, RabbitMq rabbitMq) {
        return new TopicExchange(exchangeName);
    }

    @Override
    protected Binding initBinding(Queue queue, AbstractExchange exchange, String routingKey, RabbitMq rabbitMq) {
        // 绑定队列到主题交换机，使用指定的路由键
        return BindingBuilder.bind(queue).to((TopicExchange) exchange).with(routingKey);
    }
}
